package com.tbitsglobal.server;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Queue;

import javax.servlet.http.HttpSession;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.sun.tools.example.debug.bdi.SessionListener;
import com.tbitsglobal.client.TalkService;

public class TalkServiceImpl extends RemoteServiceServlet implements TalkService{
	static Queue<String> theMessageQueue = new LinkedList<String>();

	public Boolean add(String messages) {
		return theMessageQueue.add(messages);
	}

	public String remove() {
		// TODO Auto-generated method stub
		if(!theMessageQueue.isEmpty())
		{
			return theMessageQueue.remove();
		}
		return null;
	}

	static ArrayList<String> users = new ArrayList<String>();
	public String[] getUsers() {
		// TODO Auto-generated method stub
		return users.toArray(new String[0]);
	}

	static Hashtable<String, String> waitingChats = new Hashtable<String, String>();
	public boolean requestChat(String name) {
		// TODO Auto-generated method stub
		return false;
	}

	public Boolean tryCreatingNick(String nick) {
		// TODO Auto-generated method stub
		return null;
	}

	public String[] getWaitingTalksForMe(String nick) {
		// TODO Auto-generated method stub
		return null;
	}

	public Boolean login(String nickName) {
		HttpSession session = super.getThreadLocalRequest().getSession();
		session.setAttribute("user", nickName);
		return true;
	}
}
